﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/BaseMaster/Pages.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Liu_Project.Web.Admin.Pages.Personal.EntMenu.Index" %>

<asp:Content ID="Content1" ContentPlaceHolderID="baseTitle" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="baseHead" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="baseContent" runat="server">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">菜单预览树</div>
                <div class="layui-card-body" style="height: 100%;">
                    <div style="padding: 10px; overflow: auto;">
                        <ul id="menuTree" class="dtree" data-id="0"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md9">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table id="tableGrid" lay-filter="tbGrid" class="table_margin_0"></table>
                </div>
            </div>
        </div>

    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="baseScript" runat="server">
    <script type="text/html" id="iMenuIcon">
        <i class="layui-icon {{d.MenuIcon}}"></i>   
    </script>
    <script type="text/html" id="chbIsVisiable">
        <input type="checkbox" name="IsVisiable" value="{{d.IsVisiable}}" lay-skin="switch" lay-text="正常|禁用" disabled {{ d.IsVisiable ? 'checked' : '' }}>
    </script>
    <script>
        //扩展模块初始化
        layui.use(['dtree'], function () {
            layui.dtree.render({
                elem: "#menuTree",
                url: bootPATH + "Admin/Handler/Personal/EntRoleHand.ashx", // 使用url加载（可与data加载同时存在）
                dataStyle: "layuiStyle",  //使用layui风格的数据格式
                dataFormat: "list",  //配置data的风格为list
                request: { act: "LoadList", Type: "U", IsVisiable: 0, Id: <%=CurrentUser.UserId%> },
                response: { message: "msg", statusCode: 1, treeId: "MenuId", parentId: "ParentId", title: "MenuName" },//修改response中返回数据的定义
                height: 'full-103',
                ficon: 2,
                icon: 4,
                initLevel: 1,
                menubar: true,
                menubarTips: {
                    group: ["moveDown", "moveUp", "refresh", "checkAll", "unCheckAll", "invertAll", "searchNode"], //按钮组
                },
                line: true, // 显示树线
                done: function (res, $ul, first) {

                }
            });

            layui.dtree.on("node('menuTree')", function (obj) {
                layui.table.reload('tableGrid', {
                    url: bootPATH + '/Admin/Handler/BaseHand/MenuHand.ashx',
                    where: { act: "LoadPage", Data: JSON.stringify(obj.childParams) }
                });
            });

            let tableOption = {
                elem: '#tableGrid',
                url: bootPATH + '/Admin/Handler/BaseHand/MenuHand.ashx',
                where: { act: "LoadPage" },
                height: 'full-40',//表格容器距离浏览器顶部和底部的距离“和”，加上面板上下内边距40px
                cols: [[
                    //{ type: 'checkbox', fixed: true },
                    {
                        fixed: true, title: '<input type="checkbox" name="layTableCheckbox" lay-skin="primary" lay-filter="layTableAllChoose">', width: 48, templet: '<div><input type="checkbox" lay-skin="primary" name="layTableCheckbox"></div>'
                    },
                    { type: 'numbers', title: '序号', fixed: true },
                    { field: 'ParentMenuName', title: '上级菜单名称', minWidth: 130, sort: true },
                    { field: 'MenuCode', title: '菜单代码', minWidth: 120, sort: true },
                    { field: 'MenuName', title: '菜单名称', minWidth: 120, sort: true },
                    { field: 'Level', title: '层级', minWidth: 30, sort: true },
                    { field: 'Action', title: '活动', minWidth: 180, sort: true },
                    { field: 'MenuIcon', title: '图标', minWidth: 60, sort: true, templet: '#iMenuIcon' },
                    { field: 'IsVisiable', title: '是否禁用', minWidth: 100, sort: true, templet: '#chbIsVisiable' },
                    { field: 'CreateTime', title: '创建时间', minWidth: 160, sort: true, templet: '#txtCreateTime' },
                    { field: 'CreateUserName', title: '创建人', minWidth: 120, sort: true, templet: '#txtCreateUserName' },
                    { field: 'UpdateTime', title: '最后修改时间', minWidth: 160, sort: true, templet: '#txtUpdateTime' },
                    { field: 'UpdateUserName', title: '最后修改人', minWidth: 120, sort: true, templet: '#txtUpdateUserName' }
                ]],
            };

            table_render(tableOption);//加载表格数据

            layui.table.on('toolbar(tbGrid)', function (obj) {
                let checkData = layui.table.checkStatus(obj.config.id);
                if ((obj.event != "Add") && checkData.data.length == 0) {
                    top.layer.msg('请选择数据,再操作!', function () { });
                    return;
                }
                switch (obj.event) {
                    case 'Edit':
                        {
                            layer.open({
                                type: 2,
                                id: 0,
                                title: checkData.data[0].MenuName,
                                content: "MenuDetail.aspx",
                                area: ['600px', '370px'],
                                success: function (layero, index) {
                                    var iframeWindow = window['layui-layer-iframe' + index];
                                    iframeWindow.setData(checkData.data[0]);
                                }
                            });
                        }
                        break;
                    case 'Enable':
                        top.layer.confirm('确定启用吗?', { icon: 3, title: '提示' }, function (index) {
                            let id_Arr = [];
                            for (var i = 0; i < checkData.data.length; i++) {
                                id_Arr.push(checkData.data[i].MenuId);
                            }
                            UpdateMenuVisiable(id_Arr, 1)
                        });
                        break;
                    case 'Disable':
                        top.layer.confirm('确定禁用吗?', { icon: 3, title: '提示' }, function (index) {
                            let id_Arr = [];
                            for (var i = 0; i < checkData.data.length; i++) {
                                id_Arr.push(checkData.data[i].MenuId);
                            }
                            UpdateMenuVisiable(id_Arr, 0)
                        });
                        break;
                };
            });

            function UpdateMenuVisiable(id_Arr, type) {
                top.layer.load(1);
                GetObjectInfoFunction_Async("Admin/Handler/BaseHand/MenuHand.ashx", {
                    "act": "UpdateMenuVisiable", "Data": id_Arr.toString(), IsVisiable: type
                }, function (result) {
                    top.layer.close(index);
                    top.layer.msg('操作成功 ' + result.data + ' 条');
                    layui.table.reload("tableGrid");
                })
            };
        });
    </script>
</asp:Content>
